﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbImagesTest and is intended
    ///     to contain all TmdbImagesTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbImagesTest
    {
        /// <summary>
        ///     A test for TmdbImages Constructor
        /// </summary>
        [TestMethod]
        public void TmdbImagesConstructorTest()
        {
            var target = new TmdbImages();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Backdrops
        /// </summary>
        [TestMethod]
        public void BackdropsTest()
        {
            var target = new TmdbImages();
            var expected = new List<TmdbImage>();
            target.Backdrops = expected;
            var actual = target.Backdrops;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Id
        /// </summary>
        [TestMethod]
        public void IdTest()
        {
            var target = new TmdbImages();
            int expected = new Random().Next( 0, Int32.MaxValue );
            int actual;
            target.Id = expected;
            actual = target.Id;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Posters
        /// </summary>
        [TestMethod]
        public void PostersTest()
        {
            var target = new TmdbImages();
            var expected = new List<TmdbImage>();
            target.Posters = expected;
            var actual = target.Posters;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\movieImages.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbImages();
            var jsonContent = File.ReadAllText( "movieImages.json.txt" );
            var actual = await target.DeserializeJson<TmdbImages>( jsonContent );

            Assert.AreEqual( 550, actual.Id );
            Assert.AreEqual( 4, actual.Backdrops.Count );
            Assert.AreEqual( 2, actual.Posters.Count );

            Assert.AreEqual( "/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg", actual.Backdrops[ 0 ].FilePath );
            Assert.AreEqual( 1280, actual.Backdrops[ 0 ].Width );
            Assert.AreEqual( 720, actual.Backdrops[ 0 ].Height );
            Assert.AreEqual( null, actual.Backdrops[ 0 ].Iso639_1 );
            Assert.AreEqual( 1.78, actual.Backdrops[ 0 ].AspectRatio );
            Assert.AreEqual( 5.51921973608721, actual.Backdrops[ 0 ].VoteAverage );
            Assert.AreEqual( 20, actual.Backdrops[ 0 ].VoteCount );

            Assert.AreEqual( "/hNFMawyNDWZKKHU4GYCBz1krsRM.jpg", actual.Backdrops[ 1 ].FilePath );
            Assert.AreEqual( 1280, actual.Backdrops[ 1 ].Width );
            Assert.AreEqual( 720, actual.Backdrops[ 1 ].Height );
            Assert.AreEqual( "de", actual.Backdrops[ 1 ].Iso639_1 );
            Assert.AreEqual( 1.78, actual.Backdrops[ 1 ].AspectRatio );
            Assert.AreEqual( 5.44642857142857, actual.Backdrops[ 1 ].VoteAverage );
            Assert.AreEqual( 17, actual.Backdrops[ 1 ].VoteCount );

            Assert.AreEqual( "/10zQ8ldQ4aHNOrAnY5B9wxsYFLJ.jpg", actual.Backdrops[ 2 ].FilePath );
            Assert.AreEqual( 1024, actual.Backdrops[ 2 ].Width );
            Assert.AreEqual( 1448, actual.Backdrops[ 2 ].Height );
            Assert.AreEqual( "en", actual.Backdrops[ 2 ].Iso639_1 );
            Assert.AreEqual( 0.71, actual.Backdrops[ 2 ].AspectRatio );
            Assert.AreEqual( 4.93803000652316, actual.Backdrops[ 2 ].VoteAverage );
            Assert.AreEqual( 10, actual.Backdrops[ 2 ].VoteCount );

            Assert.AreEqual( "/eQq7fKMBWK7mM4p7J6R94Hv80ps.jpg", actual.Backdrops[ 3 ].FilePath );
            Assert.AreEqual( 930, actual.Backdrops[ 3 ].Width );
            Assert.AreEqual( 1240, actual.Backdrops[ 3 ].Height );
            Assert.AreEqual( "fr", actual.Backdrops[ 3 ].Iso639_1 );
            Assert.AreEqual( 0.75, actual.Backdrops[ 3 ].AspectRatio );
            Assert.AreEqual( 0, actual.Backdrops[ 3 ].VoteAverage );
            Assert.AreEqual( 0, actual.Backdrops[ 3 ].VoteCount );

            Assert.AreEqual( "/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg", actual.Posters[ 0 ].FilePath );
            Assert.AreEqual( 1280, actual.Posters[ 0 ].Width );
            Assert.AreEqual( 720, actual.Posters[ 0 ].Height );
            Assert.AreEqual( null, actual.Posters[ 0 ].Iso639_1 );
            Assert.AreEqual( 1.78, actual.Posters[ 0 ].AspectRatio );
            Assert.AreEqual( 5.51921973608721, actual.Posters[ 0 ].VoteAverage );
            Assert.AreEqual( 40, actual.Posters[ 0 ].VoteCount );

            Assert.AreEqual( "/hNFMawyNDWZKKHU4GYCBz1krsRM.jpg", actual.Posters[ 1 ].FilePath );
            Assert.AreEqual( 1280, actual.Posters[ 1 ].Width );
            Assert.AreEqual( 720, actual.Posters[ 1 ].Height );
            Assert.AreEqual( null, actual.Posters[ 1 ].Iso639_1 );
            Assert.AreEqual( 1.78, actual.Posters[ 1 ].AspectRatio );
            Assert.AreEqual( 5.44642857142857, actual.Posters[ 1 ].VoteAverage );
            Assert.AreEqual( 119, actual.Posters[ 1 ].VoteCount );
        }
    }
}